package com.hand.service;

import com.hand.entity.Condition;
import com.hand.entity.Pagination;
import com.hand.entity.SsmItem;
import com.hand.mapper.SsmItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigInteger;
import java.util.List;

/**
 * Created by 86136 on 2019/7/19.
 */

@Service
public class ItemService {
    @Autowired
    private SsmItemMapper itemMapper;

    @Transactional
    public int count(Condition condition){
        return itemMapper.count(condition);
    }

    @Transactional
    public List<SsmItem> selectByCondition(Condition condition, Pagination pagination) {
        return itemMapper.selectByCondition(condition,pagination);
    }

    @Transactional
    public int updateItem(SsmItem ssmItem) {
        return itemMapper.updateItem(ssmItem);
    }

    @Transactional
    public int insertItem(SsmItem ssmItem){
        BigInteger bigInteger = new BigInteger("1");

        ssmItem.setObjectVersionNumber(bigInteger);
        ssmItem.setCreationDate(ssmItem.getStartActiveDate());
        ssmItem.setLastUpdateDate(ssmItem.getEndActiveDate());
        ssmItem.setLastUpdatedBy(bigInteger);
        ssmItem.setCreatedBy(bigInteger);
        return itemMapper.insertItem(ssmItem);
    }

    @Transactional
    public int deleteItem(BigInteger itemIds) {
        return itemMapper.deleteItem(itemIds);
    }
}
